package yxy.game.pm2.module.tip.checker;

import java.util.HashSet;
import java.util.Set;

import yxy.apple.util.PubSub.MethodSubscriber;
import yxy.apple.util.PubSub.SubscriptionMethod;
import yxy.cherry.data.DataCenter;
import yxy.cherry.data.bean.weapongrade;
import yxy.game.pm2.bean.Currency;
import yxy.game.pm2.bean.currency.CurrencyType;
import yxy.game.pm2.bean.pubsub.CurrencyPublisher;
import yxy.game.pm2.bean.pubsub.CurrencyPublisher.CurrencySubscription;
import yxy.game.pm2.module.CurrencyHandle;
import yxy.game.pm2.module.niubee.NiuBeeModule;
import yxy.game.pm2.module.tip.TipHandle;
import yxy.game.pm2.module.tip.TipType;

public class TipSubscriber_神器铸魂 extends MethodSubscriber {

	static private TipSubscriber_神器铸魂 instance;

	public static TipSubscriber_神器铸魂 getInstance() {
		if (instance == null) {
			instance = new TipSubscriber_神器铸魂();
			instance.init();
		}
		return instance;
	}

	private void init() {
		CurrencyPublisher.getInstance().subscribe(this);
	}

	private TipSubscriber_神器铸魂() {
	}

	@SubscriptionMethod(Type = CurrencySubscription.class)
	public void receive(CurrencySubscription subscription) {
//		System.err.println("订阅更新Task");
		String playerCode = subscription.getPlayerCode();
		if (!subscription.checkTypes(allowType())) {
			return;
		}
		new TipHandle().updateTip(playerCode, TipType.神器_铸魂按钮, check(playerCode));
	}

	private boolean check(String playerCode) {
		NiuBeeModule module = NiuBeeModule.get(playerCode);
		if (module.getProgress() < 5) {
			return false;
		}
		int soul = module.getSoulLevel();
		weapongrade data = DataCenter.getData(module.getLevel(), weapongrade.class);
		int max = data.getCastmax();
		if (soul + 1 >= max) {
			return false;
		}
		// 道具固定1029
		Currency cost = Currency.create(CurrencyType.CT_物品, 1029, 1);

		boolean cancost = new CurrencyHandle().costCheck(playerCode, cost);
		return cancost;
	}

	private Set<CurrencyType> allowTypes;

	private Set<CurrencyType> allowType() {
		if (allowTypes != null) {
			return allowTypes;
		}
		allowTypes = new HashSet<>();

		allowTypes.add(CurrencyType.CT_物品);

		return allowTypes;
	}
}
